package algorithm.sort;

import java.util.Arrays;

/**
 * @ClassName : data_structure.TestSort.ShellSort
 * @Description : 类描述
 * Created by cyd on 2021-02-22 23:48:12
 */
public class ShellSort {
    public static void sort(int[] arr) {
        int length = arr.length;
        int temp;
        for (int step = length / 2; step >= 1; step /= 2) {
            for (int i = step; i < length; i++) {
                temp = arr[i];
                int j = i - step;
                while (j >= 0 && arr[j] > temp) {
                    arr[j + step] = arr[j];
                    j -= step;
                }
                arr[j + step] = temp;
            }
        }
    }

    public static void main(String[] args) {
        int[] ints = {1, 3, 5, 7, 9, 2, 4, 6, 8, 0, -1};
        ShellSort.sort(ints);
        System.out.println(Arrays.toString(ints));
    }
}
